package com.workmanager.service;

import com.sun.xml.internal.ws.api.pipe.FiberContextSwitchInterceptor;
import com.workmanager.bean.JobTaskBean;
import com.workmanager.bean.WorkBean;
import com.workmanager.mapper.WorkFileMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dana on 2016/8/31.
 */
@Service("workFileService")
public class WorkFileService {
    private WorkFileMapper workFileMapper;
    /**
     * 该方法用于上传作业
     * @return
     */
    public boolean uploadfile(WorkBean work){
        Map para=new HashMap();
        para.put("studentid",work.getStudent_id());
        para.put("jobtaskid",work.getJobTask_id());
        para.put("date",work.getWork_date());
        para.put("file",work.getWork_file());
        para.put("title",work.getWork_title());
        para.put("goodjob",work.getWork_goodjob());
        boolean result = ifstuhaswork(para);
        if(result){
            workFileMapper.uploadfileupdate(para);
        }else{
            work.setWork_id(String.valueOf(getworkpk()));
            para.put("workid",work.getWork_id());
            workFileMapper.uploadfile(para);
        }
        return true;
    }

    /**
     * 该方法用于判断学生之前是否提交过该jobTask_id的作业
     * @param para
     * @return true表示之前交过作业
     */
    public boolean ifstuhaswork(Map para){
        return  workFileMapper.ifstuhaswork(para)!=0;
    }

    /**
     * 该方法用于得到该学生班级的全部作业任务
     * @param studentid
     * @return
     */
    public List<JobTaskBean> getworksbystudentid(int studentid){
        return workFileMapper.getworksbystudentid(studentid);
    }

    /**
     * 该方法用于得到该学生上交的全部作业
     * @return
     */
    public List<WorkBean> getstudentworks(int studentid){
        return workFileMapper.getstudentworks(studentid);
    }

    /**
     *该方法用于获取该老师布置的所有任务
     * @param teacherid
     * @return
     */
    public List<JobTaskBean> getjobtasksbyteacherid(int teacherid){
        return workFileMapper.getjobtasksbyteacherid(teacherid);
    }

    /**
     * 该方法用于取消分享优秀作业
     * @param jobworkid
     * @return
     */
    public boolean stopsharegoodwork(int jobworkid){
        workFileMapper.stopsharegoodwork(jobworkid);
        return true;
    }

    public int getworkpk(){
        return workFileMapper.getworkpk();
    }

    public List<WorkBean> getgoodworksbyjobid(int jobid){
        return workFileMapper.getgoodworksbyjobid(jobid);
    }

    public WorkFileMapper getWorkFileMapper() {
        return workFileMapper;
    }

    public void setWorkFileMapper(WorkFileMapper workFileMapper) {
        this.workFileMapper = workFileMapper;
    }
}
